<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=<device-width>, initial-scale=1.0">
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.0.2/css/bootstrap-grid.css" rel="stylesheet">
    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.js
    "></script>
    <title>Document</title>
</head>
<body>
    <div class="container">
        <h2 class="page-header">基本使用</h2>
        <button class="btn btn-primary">发送GET请求</button>
        <button class="btn btn-primary">发送POST请求</button>
        <button class="btn btn-primary">发送PUT请求</button>
        <button class="btn btn-primary">发送DELETE请求</button>
    </div>
    <script>
        //获取按钮
        const btns=document.querySelectorAll('button');
        //axios
        btns[0].onclick=function(){
            //发送ajax请求
           axios.request({
               method:'GET',
               url:"http://localhost:3000/comments"
           }).then(response=>{
                console.log(response);
           }) ;
        }
        //post
        btns[1].onclick=function(){
            axios.post(
                'http://localhost:3000/comments',   
                {
                    "body": "普天同庆",
                    "postId": 2
                }
            ).then(response=>{
                console.log(response);

            });
        }
        /***
         * axios({
         *          url:'/post',
         *          //   /post?a=10&b=200
         *          //   /post/a/100/b/200
         *          //   /post/a.100/b.200
         *          params{
         *              a:100,
         *              b:100
         *          }
         * })
         ***/
    </script>
</body>
</html>